﻿using CyberConnect.Insteon.Messaging;
using System;

namespace CyberConnect.Insteon.Devices
{
    public class ApplianceLinc : InsteonDevice, IRelay, IInsteonDevice
    {
        public ApplianceLinc(DeviceAddress address)
            : base(address, 0x02, 0x09) { }

        public ApplianceLinc(string address)
            : this(new DeviceAddress(address)) { }

        private static readonly MessageCommand OnCommand = (MessageCommand)0x12FF;
        private static readonly MessageCommand OffCommand = (MessageCommand)0x1400;
        private static readonly MessageConfiguration Configuration = new MessageConfiguration(MessageType.Direct, false);

        public void SwitchOnOff(PlmLinc link, bool state)
        {
            if (link == null) { throw new ArgumentNullException("link"); }

            link.SendDeviceMessage(new DeviceMessage(this.Address, ApplianceLinc.Configuration, state ? ApplianceLinc.OnCommand : ApplianceLinc.OffCommand));
        }
    }
}